|
|
|
|
|
|
|
center of projection. Other parts of the surface cannot block the view of these edges, so you know that these edges should be drawn. In Figure 14.10 these two edges are drawn with heavy lines. |
|
|
|
|
|
|
|
|
Once you have drawn the front edges, you can begin drawing the bent rectangles that make up the rest of the surface. You can draw them ordered by their X and Z values, with rows of ''rectangles" having the same X values drawn first. Figure 14.11 shows the same surface as Figure 14.10, with the first row and part of the second outlined with heavy lines to show you the order in which they should be drawn. |
|
|
|
|
|
|
|
|
Because each area you draw has larger X or Z values than all of the areas you have not yet drawn, you know that the undrawn areas cannot obscure the one you are drawing. If you follow the pattern of drawing areas in Figure 14.11, you will find that some areas are obscured by areas you have already drawn. None is covered by an area that you will draw later, however. |
|
|
|
|
|
|
|
|
To make this drawing method into a hidden surface removal algorithm, you still need to take into account the cases in which an area you draw later is covered by one you have already drawn. This is where the "Hi-Lo" comes in. To keep track of the parts of the screen that are already covered by an area, you create two arrays: hi and lo. For each X value in your projected surface, the lo entry records the smallest Y coordinate value used so far on the screen. The corresponding hi entry records the greatest Y value used so far on the screen. |
|
|
|
|
|
|
|
|
As you prepare to display a new area, you check to see if the points you need to draw fall between the array values lo and hi. If you need to plot the point (a, b) on the screen, for example, you check to see if lo(a) <= b <= hi(a). If so, the point (a, b) is obscured by a previously drawn area, so you do not draw the point. |
|
|
|
|
|
|
|
|
In practice, it is faster to examine the line segments that define a region than to examine all the points it contains. To draw a line segment, start at one of the segment's endpoints. Move along the segment, one X coordinate value at a time, checking to see if the segment has moved into or out of the range spanned by the hi and lo values. Draw the portions of the segment that are visible. Whenever you find a point that lies above the corresponding hi value, update hi to have the new value. Similarly, when you find a point that lies below the corresponding lo value, update lo to have the new value. |
|
|
|
|
|
|
|
|
Figure 14.11
In the Hi-Lo algorithm, areas are drawn from front to back. |
|
|
|
|
|